﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using AttributeRouting.Web.Http;
using WS.EKA.Core.DI;
using WS.EKA.Model;
using WS.EKA.ServiceInterface;
using WS.EKA.Utilities.Consts;
using WS.EKA.Portal.Filters;
using System.Net;

namespace WS.EKA.Portal.Controllers
{
    [AuthencationFilter(true)]
    public class MemberAddressController : ControllerBase
    {
        IMemberAddress addressService;
        public MemberAddressController(IMemberAddress addressService)
        {
            this.addressService = addressService;
        }

        [GET("api/address/{loginId}")]
        public List<MemberAddress> Get(string loginId)
        {
            return addressService.GetListByMember(loginId);
        }

        [POST("api/address/")]
        public HttpStatusCode Post(MemberAddress memberAddress)
        {
            try
            {
                string userLoginId = GetCurrentUser();
                memberAddress.MemLoginID =userLoginId;
                memberAddress.CreateUser=userLoginId;
                memberAddress.ModifyUser=userLoginId;
                addressService.Add(memberAddress);
                return HttpStatusCode.Created;
            }
            catch
            {
                return HttpStatusCode.ExpectationFailed;
            }
        }
    }
}